package myutils

import (
	"gopkg.in/ini.v1"
)

var (
	AppMode        string
	HttpPost       string
	ConnectionInfo string
	JWTKey         string
	ValidityPeriod int
	DataBase       string
	SurvivalTime   int
	PrivateHost    string
	WeatheCode     string
)

func init() {
	f, err := ini.Load("config/config.ini")
	if err != nil {
		panic("配置文件读取失败")
	}
	loadGin(f)
	loadGorm(f)
	loadRedis(f)
	loadOther(f)
}
func loadGin(file *ini.File) {
	AppMode = file.Section("gin").Key("AppMode").MustString("debug")
	HttpPost = file.Section("gin").Key("HttpPost").MustString(":2333")

}
func loadGorm(file *ini.File) {
	ConnectionInfo = file.Section("gorm").Key("ConnectionInfo").MustString("ConnectionInfo=root:admin123@tcp(127.0.0.1:3306)/default?charset=utf8mb4&parseTime=true&loc=Local")
	DataBase = file.Section("gorm").Key("Database").MustString("default")
}
func loadRedis(file *ini.File) {
}
func loadOther(file *ini.File) {
	JWTKey = file.Section("jwt").Key("JWTKey").MustString("1232123")
	ValidityPeriod = file.Section("jwt").Key("ValidityPeriod").MustInt(8)
	SurvivalTime = file.Section("log").Key("SurvivalTime").MustInt(24)
	PrivateHost = file.Section("host").Key("PrivateHost").MustString("localhost:2333")
	WeatheCode = file.Section("weather").Key("WeatheCode").MustString("101190101")
}
